<?php
/**
 * @file indigo/framework/classes/Module.php
 * Contains the definition of the abstract Module class
 */
  namespace indigo\framework;
  
 /**
  * @class Module
  * Abstract class that defines the basic methods each Indigo module is expected to have
  */
	abstract class Module
	{
   /**
    * Class constant that contains an alphanumeric representation of the module name that is expected to be globally unique
    * @attention The value of this constant MUST be the same as the directory name of the module
    */
    const NAME = null;
    
   /**
    * Loads the modules settings file
    *
    * @retval true if the file is found
    * @retval false if otherwise
    *
    * @note %Module settings file are expected to be placed in the /config directory of the module and named "settings.php"
    */
		public function loadSettings()
		{
      // module settings file expects the $module variable which contains the current module
      $module = $this;
      
			$moduleName = static::NAME;
      
			if (file_exists("modules/$moduleName/config/settings.php")) {
				require_once "modules/$moduleName/config/settings.php";
				return true;
			}	else {
				return false;
      }
		}
		
   /**
    * Default initialize method for Module classes.
    *
    * Simply returns true if not overridden
    *
    * @note When overriden, functions MUST return a boolean value indicating success or failure of initization
    * @retval true if the initialization succeeds
    * @retval false if the initialization fails
    */
		public function initialize()
    {
      return true;
    }
    
   /**
    * Entry point for all modules.
    *
    * Defined as abstract, inheriting classes MUST implement this function. It is called immediately after initialization by the Router class
    *
    * @param $args an array of all arguments passed to the module by the Router class
    * @see Router::dispatch() for more details on how $args is built
    */
		abstract public function execute($args);
	}